package {
	import flash.display.Sprite;
	
	public class XmlExample extends Sprite {        
		public function XmlExample() {
			var employees:XML =
				<employees>
					<employee ssn="123-123-1234">
						<name first="John" last="Doe"/>
						<address>
							<street>11 Main St.</street>
							<city>San Francisco</city>
							<state>CA</state>
							<zip>98765</zip>
						</address>
					</employee>
					<employee ssn="789-789-7890">
						<name first="Mary" last="Roe"/>
						<address>
							<street>99 Broad St.</street>
							<city>Newton</city>
							<state>MA</state>
							<zip>01234</zip>
						</address>
					</employee>
				</employees>;
			
			trace(employees.employee[0].address.zip);   // 98765
			
			trace(employees.employee[1].@ssn);          // 789-789-7890
			
			trace(employees.employee.name);             // <name first="John" last="Doe"/>
			// <name first="Mary" last="Roe"/>
			
			trace(employees..zip[0]);                   // 98765
			
			trace(employees..@ssn[1]);                  // 789-789-7890
			
			trace(employees..name);                     // <name first="John" last="Doe"/>
			// <name first="Mary" last="Roe"/>
			
			trace(employees.employee[0].address.*);     // <street>11 Main St.</street>    
			// <city>San Francisco</city>
			// <state>CA</state>
			// <zip>98765</zip>
			var node:String = "zip";
			trace(employees.employee[0].address[node]); // 98765
			
			var attribute:String = "ssn";
			trace(employees.employee[1].@[attribute]);  // 789-789-7890
			
			for each (var num:XML in employees..@ssn) {
				trace(num);                             // 123-123-1234
			}                                           // 789-789-7890
			
			var ssnToFind:String = "789-789-7890";
			trace(employees.employee.(@ssn == ssnToFind).toXMLString());
			// <employee ssn="789-789-7890">
			// <name first="Mary" last="Roe"/>
			// <address>
			// <street>99 Broad St.</street>
			// <city>Newton</city>
			// <state>MA</state>
			// <zip>01234</zip>
			// </address>
			// </employee>
		}
	}
}
